package cn.stylefeng.guns.modular.weixin.controller;

import com.github.binarywang.wxpay.service.*;
import org.springframework.beans.factory.annotation.*;
import com.github.binarywang.wxpay.exception.*;
import io.swagger.annotations.*;
import org.springframework.web.bind.annotation.*;
import com.github.binarywang.wxpay.bean.notify.*;
import java.io.*;
import com.github.binarywang.wxpay.bean.request.*;
import com.github.binarywang.wxpay.bean.result.*;
import com.github.binarywang.wxpay.bean.coupon.*;
import java.util.*;

@Api("\u5fae\u4fe1\u652f\u4ed8")
@RestController
@RequestMapping({ "/pay" })
public class WxPayController
{
    private WxPayService wxService;
    
    @Autowired
    public WxPayController(final WxPayService wxService) {
        this.wxService = wxService;
    }
    
    @ApiOperation("\u67e5\u8be2\u8ba2\u5355")
    @GetMapping({ "/queryOrder" })
    public WxPayOrderQueryResult queryOrder(@RequestParam(required = false) final String transactionId, @RequestParam(required = false) final String outTradeNo) throws WxPayException {
        return this.wxService.queryOrder(transactionId, outTradeNo);
    }
    
    @ApiOperation("\u67e5\u8be2\u8ba2\u5355")
    @PostMapping({ "/queryOrder" })
    public WxPayOrderQueryResult queryOrder(final WxPayOrderQueryRequest wxPayOrderQueryRequest) throws WxPayException {
        return this.wxService.queryOrder(wxPayOrderQueryRequest);
    }
    
    @ApiOperation("\u5173\u95ed\u8ba2\u5355")
    @GetMapping({ "/closeOrder/{outTradeNo}" })
    public WxPayOrderCloseResult closeOrder(@PathVariable final String outTradeNo) throws WxPayException {
        return this.wxService.closeOrder(outTradeNo);
    }
    
    @ApiOperation("\u5173\u95ed\u8ba2\u5355")
    @PostMapping({ "/closeOrder" })
    public WxPayOrderCloseResult closeOrder(final WxPayOrderCloseRequest wxPayOrderCloseRequest) throws WxPayException {
        return this.wxService.closeOrder(wxPayOrderCloseRequest);
    }
    
    @ApiOperation("\u7edf\u4e00\u4e0b\u5355\uff0c\u5e76\u7ec4\u88c5\u6240\u9700\u652f\u4ed8\u53c2\u6570")
    @PostMapping({ "/createOrder" })
    public <T> T createOrder(@RequestBody final WxPayUnifiedOrderRequest request) throws WxPayException {
        return (T)this.wxService.createOrder(request);
    }
    
    @ApiOperation("\u539f\u751f\u7684\u7edf\u4e00\u4e0b\u5355\u63a5\u53e3")
    @PostMapping({ "/unifiedOrder" })
    public WxPayUnifiedOrderResult unifiedOrder(@RequestBody final WxPayUnifiedOrderRequest request) throws WxPayException {
        return this.wxService.unifiedOrder(request);
    }
    
    @ApiOperation("\u9000\u6b3e")
    @PostMapping({ "/refund" })
    public WxPayRefundResult refund(@RequestBody final WxPayRefundRequest request) throws WxPayException {
        return this.wxService.refund(request);
    }
    
    @ApiOperation("\u9000\u6b3e\u67e5\u8be2")
    @GetMapping({ "/refundQuery" })
    public WxPayRefundQueryResult refundQuery(@RequestParam(required = false) final String transactionId, @RequestParam(required = false) final String outTradeNo, @RequestParam(required = false) final String outRefundNo, @RequestParam(required = false) final String refundId) throws WxPayException {
        return this.wxService.refundQuery(transactionId, outTradeNo, outRefundNo, refundId);
    }
    
    @ApiOperation("\u9000\u6b3e\u67e5\u8be2")
    @PostMapping({ "/refundQuery" })
    public WxPayRefundQueryResult refundQuery(final WxPayRefundQueryRequest wxPayRefundQueryRequest) throws WxPayException {
        return this.wxService.refundQuery(wxPayRefundQueryRequest);
    }
    
    @ApiOperation("\u652f\u4ed8\u56de\u8c03\u901a\u77e5\u5904\u7406")
    @PostMapping({ "/notify/order" })
    public String parseOrderNotifyResult(@RequestBody final String xmlData) throws WxPayException {
        final WxPayOrderNotifyResult notifyResult = this.wxService.parseOrderNotifyResult(xmlData);
        return WxPayNotifyResponse.success("\u6210\u529f");
    }
    
    @ApiOperation("\u9000\u6b3e\u56de\u8c03\u901a\u77e5\u5904\u7406")
    @PostMapping({ "/notify/refund" })
    public String parseRefundNotifyResult(@RequestBody final String xmlData) throws WxPayException {
        final WxPayRefundNotifyResult result = this.wxService.parseRefundNotifyResult(xmlData);
        return WxPayNotifyResponse.success("\u6210\u529f");
    }
    
    @ApiOperation("\u626b\u7801\u652f\u4ed8\u56de\u8c03\u901a\u77e5\u5904\u7406")
    @PostMapping({ "/notify/scanpay" })
    public String parseScanPayNotifyResult(final String xmlData) throws WxPayException {
        final WxScanPayNotifyResult result = this.wxService.parseScanPayNotifyResult(xmlData);
        return WxPayNotifyResponse.success("\u6210\u529f");
    }
    
    @ApiOperation("\u53d1\u9001\u7ea2\u5305")
    @PostMapping({ "/sendRedpack" })
    public WxPaySendRedpackResult sendRedpack(@RequestBody final WxPaySendRedpackRequest request) throws WxPayException {
        return this.wxService.sendRedpack(request);
    }
    
    @ApiOperation("\u67e5\u8be2\u7ea2\u5305")
    @GetMapping({ "/queryRedpack/{mchBillNo}" })
    public WxPayRedpackQueryResult queryRedpack(@PathVariable final String mchBillNo) throws WxPayException {
        return this.wxService.queryRedpack(mchBillNo);
    }
    
    public byte[] createScanPayQrcodeMode1(final String productId, final File logoFile, final Integer sideLength) {
        return this.wxService.createScanPayQrcodeMode1(productId, logoFile, sideLength);
    }
    
    public String createScanPayQrcodeMode1(final String productId) {
        return this.wxService.createScanPayQrcodeMode1(productId);
    }
    
    public byte[] createScanPayQrcodeMode2(final String codeUrl, final File logoFile, final Integer sideLength) {
        return this.wxService.createScanPayQrcodeMode2(codeUrl, logoFile, sideLength);
    }
    
    @ApiOperation("\u63d0\u4ea4\u4ea4\u6613\u4fdd\u969c\u6570\u636e")
    @PostMapping({ "/report" })
    public void report(@RequestBody final WxPayReportRequest request) throws WxPayException {
        this.wxService.report(request);
    }
    
    @ApiOperation("\u4e0b\u8f7d\u5bf9\u8d26\u5355")
    @GetMapping({ "/downloadBill/{billDate}/{billType}/{tarType}/{deviceInfo}" })
    public WxPayBillResult downloadBill(@PathVariable final String billDate, @PathVariable final String billType, @PathVariable final String tarType, @PathVariable final String deviceInfo) throws WxPayException {
        return this.wxService.downloadBill(billDate, billType, tarType, deviceInfo);
    }
    
    @ApiOperation("\u4e0b\u8f7d\u5bf9\u8d26\u5355")
    @PostMapping({ "/downloadBill" })
    public WxPayBillResult downloadBill(final WxPayDownloadBillRequest wxPayDownloadBillRequest) throws WxPayException {
        return this.wxService.downloadBill(wxPayDownloadBillRequest);
    }
    
    @ApiOperation("\u63d0\u4ea4\u5237\u5361\u652f\u4ed8")
    @PostMapping({ "/micropay" })
    public WxPayMicropayResult micropay(@RequestBody final WxPayMicropayRequest request) throws WxPayException {
        return this.wxService.micropay(request);
    }
    
    @ApiOperation("\u64a4\u9500\u8ba2\u5355")
    @PostMapping({ "/reverseOrder" })
    public WxPayOrderReverseResult reverseOrder(@RequestBody final WxPayOrderReverseRequest request) throws WxPayException {
        return this.wxService.reverseOrder(request);
    }
    
    @ApiOperation("\u83b7\u53d6\u6c99\u7bb1\u73af\u5883\u7b7e\u540dkey")
    @GetMapping({ "/getSandboxSignKey" })
    public String getSandboxSignKey() throws WxPayException {
        return this.wxService.getSandboxSignKey();
    }
    
    @ApiOperation("\u53d1\u653e\u4ee3\u91d1\u5238")
    @PostMapping({ "/sendCoupon" })
    public WxPayCouponSendResult sendCoupon(@RequestBody final WxPayCouponSendRequest request) throws WxPayException {
        return this.wxService.sendCoupon(request);
    }
    
    @ApiOperation("\u67e5\u8be2\u4ee3\u91d1\u5238\u6279\u6b21")
    @PostMapping({ "/queryCouponStock" })
    public WxPayCouponStockQueryResult queryCouponStock(@RequestBody final WxPayCouponStockQueryRequest request) throws WxPayException {
        return this.wxService.queryCouponStock(request);
    }
    
    @ApiOperation("\u67e5\u8be2\u4ee3\u91d1\u5238\u4fe1\u606f")
    @PostMapping({ "/queryCouponInfo" })
    public WxPayCouponInfoQueryResult queryCouponInfo(@RequestBody final WxPayCouponInfoQueryRequest request) throws WxPayException {
        return this.wxService.queryCouponInfo(request);
    }
    
    @ApiOperation("\u62c9\u53d6\u8ba2\u5355\u8bc4\u4ef7\u6570\u636e")
    @PostMapping({ "/queryComment" })
    public String queryComment(final Date beginDate, final Date endDate, final Integer offset, final Integer limit) throws WxPayException {
        return this.wxService.queryComment(beginDate, endDate, offset, limit);
    }
}
